//
//  duiwaixqTableViewController.m
//  PASystem
//
//  Created by michael on 16/8/22.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "duiwaixqTableViewController.h"

@interface duiwaixqTableViewController ()
@property(nonatomic,assign)int currentPage; //当前页
@property(nonatomic,strong)NSMutableArray * dataArray;
@property(nonatomic,strong)NSDictionary * dic;
@property(nonatomic,assign)int totalCounts; //总条数

@end

@implementation duiwaixqTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
//    self.tableView.layer.borderWidth = 5;
//    self.tableView.layer.borderColor = [myColor CGColor];
     self.title = _string;
    self.view.backgroundColor = [UIColor whiteColor];
            [self loadData]; //加载网络数据
self.tableView.bounces = NO;
}
-(NSMutableArray*)dataArray{
    if (_dataArray == nil) {
      _dataArray =   [NSMutableArray array];
    }
    return _dataArray;
}
#pragma mark 加载网络数据
-(void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
 NSString *json =[NSString stringWithFormat: @"{'action':%@,'service': %@, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",_action,_service,userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {

       
     NSDictionary *dic = JSON[@"reason"];
        
    NSDictionary *dict = dic[@"attrs"];
//    NSLog(@"%@",dict);
    
    _dic = dict;
    [_dataArray addObject:dict];
    

//     NSLog(@"11%@",_dataArray);
        
        [self.tableView reloadData];
       
    } failure:^(NSError *error) {
        
    }];
 
}
- (void)viewDidAppear:(BOOL)animated
{
self.tableView.frame = CGRectMake(0, 64, KScreenWidth, KScreenHeight-46-64);
     UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
    
    self.tableView.layer.borderWidth = 10;
    self.tableView.layer.borderColor = [myColor CGColor];

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

if (indexPath.row==0) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"联络处名称:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"LIAISONNAME"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==1) {
 
      UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"联络处地址:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"LIAISONADDRESS"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }

if (indexPath.row==2) {
 
      UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"境外联络方式:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"OVERSEASLIAISON"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 }
if (indexPath.row==3) {
 
    
      UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"境内联络方式:";
  //domesticliaison
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"DOMESTICLAISON"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==4) {
  UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"Email:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"EMAIL"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
 
 if (indexPath.row==5) {
 
    UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"授牌时间:";
    
    
      //时间
  NSString *string = _dic[@"AWARDINGTIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];

  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = selfYear;
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==6){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"负责人姓名:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"NAME"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
 if (indexPath.row==7){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"性别:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
 if ([[NSString stringWithFormat:@"%@",_dic[@"SEX"]]isEqualToString: @"1"]) {
        label2.text = @"男";

}if ([[NSString stringWithFormat:@"%@",_dic[@"SEX"]]isEqualToString: @"2"]) {
            label2.text = @"女";

}else{
            label2.text = @"暂无数据";

}
 
    
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==8){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"学历:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"EDUCATION"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==9){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 150, cell.contentView.height)];
    label.text = @"参加社团与职务:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -170, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"PSOT"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==10){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"企业名称:";
  //enterprisename
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"ENTERPRISENAME"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==11){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"经营范围:";
  //businessscope
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"BUSINESSSCOPE"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==12){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"经办人姓名:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"MANAGERNAME"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==13){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"经本人电话:";
  //managerstel
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"MANAGERSTEL"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==14){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"经办人Email:";
  
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, label.height)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"MANAGERSEMAIL"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==15){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"推荐机构:";
  //recommendation
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
    CGFloat titleSize = [OAToolBox sizebyText:_dic[@"RECOMMENDATION"] font:12 minsWidth:120];
if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120,titleSize)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"RECOMMENDATION"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }if (indexPath.row==16){
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"部门意见:";
  //sectoropinion
  CGFloat titleSize = [OAToolBox sizebyText:_dic[@"SECTOROPINION"] font:12 minsWidth:120];
  if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, titleSize)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"SECTOROPINION"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }else{
       UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 100, cell.contentView.height)];
    label.text = @"会意见:";
   CGFloat titleSize = [OAToolBox sizebyText:_dic[@"OPINION"] font:12 minsWidth:120];
  if (titleSize<44) {
    titleSize =  cell.height;
}else{
titleSize = titleSize;

}
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth -120, titleSize)];
 label2.numberOfLines = 0;
    label2.text = _dic[@"OPINION"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat H = 44;
if (indexPath.row == 17){
 CGFloat titleSize = [OAToolBox sizebyText:_dic[@"OPINION"] font:12 minsWidth:120];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}

if (indexPath.row == 16){
 CGFloat titleSize = [OAToolBox sizebyText:_dic[@"SECTOROPINION"] font:12 minsWidth:120];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}

if (indexPath.row == 15){
 CGFloat titleSize = [OAToolBox sizebyText:_dic[@"RECOMMENDATION"] font:12 minsWidth:120];
if (titleSize<44) {
    return 44;
}else{
return titleSize;

}
}


else{

return H;
}

}








- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 18;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
